package com.gaolang.config;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author DELLHL
 */
public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        //登入后 HttpSession 不为空
        Object loginSuccess = request.getSession().getAttribute("loginSuccess");

        if (loginSuccess == null){

            request.setAttribute("msg","<div class=\"alert alert-warning alert-dismissible\" role=\"alert\"><strong>没有权限，请先登入!</strong></div>");
            request.getRequestDispatcher("/").forward(request,response);
            return false;
        }else {
            return true;
        }

    }


}
